#pragma once 
#include <ms/http/server/TcpAccept.h>
#include <ms/http/server/Session.h>
#include <list>
namespace ms{
namespace http{
namespace server{
class ServerResponseFactory;
class CServerConfig;

class session_manager
{
public:
    session_manager(const CServerConfig& config, ServerResponseFactory* factory = NULL);
    ~session_manager();
	bool Start();
	bool Stop();

    void start_accept_session(Session* session);
	void do_start_extern_start();
	void do_start_extern_stop();
	
    void continue_work();
    Session* create_session();

    void HandleAccept(Session* session);
    void handle_accept_at_work(Session* session);
	void start_session_start(Session*);

private:
	static DWORD WINAPI ThreadProc(LPVOID lpThreadParameter);

    TcpAccept _accept;

	struct extern_state
	{
		enum value_t {ready, work, stop};
	};
	extern_state::value_t _extern_state;
	ServerResponseFactory * _serverresponsefactory;

	HANDLE _thread;
public:
	extern_state::value_t get_extern_state()
	{
		return _extern_state;
	}
};

}// server
} // http
} // ms
